package com.cl.service.impl;

import com.cl.utils.SendMailUtil;
import com.cl.utils.TimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScheduledService {
    @Autowired
    SendMailUtil sendMailUtil;
    @Autowired
    UserServiceImpl userService;
    @Autowired
    TimeUtil timeUtil;
    //秒   分   时     日   月   周几
    //0 * * * * MON-FRI
    //注意cron表达式的用法；
    @Scheduled(cron = "0 1 0 ? * *")
    @Async
    public void send(){
        String todayTime = timeUtil.getTodayTime();
        List<String> emails = userService.queryToday(todayTime);
        if (emails.size()>0){
            for (String email : emails) {
                sendMailUtil.sendSimpleMail("通知","请于"+todayTime+"来接种疫苗",email);
            }
        }
    }
    @Async
    public void sendToAge(String subject,String text,List<String> toMail){
        for (String s : toMail) {
            sendMailUtil.sendSimpleMail(subject, text, s);
        }
    }
}
